

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGSwitchWidget extends StatefulWidget {

  List<String> items;
  int index;
  final int? types;

  Function(int index) onSwitch;

  QGSwitchWidget({
    Key? key,
    this.types,
    required this.index,
    required this.items,
    required this.onSwitch,
  }) : super(key: key);

  @override
  State<QGSwitchWidget> createState() => _QGSwitchWidgetState();
}

class _QGSwitchWidgetState extends State<QGSwitchWidget> {
  @override
  Widget build(BuildContext context) {
    return
    Container(
      height: widget.types!=1?54.rpx:25.rpx,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.zero,
        itemCount: widget.items.length,
        itemBuilder: (context, i) {
          return 
          
          Container(
            margin: EdgeInsets.only(left: 10.rpx),
            child: GestureDetector(
              onTap: () {
                widget.onSwitch(i);
              },
              child: widget.types!=1?
              Container(
                 padding: EdgeInsets.symmetric(horizontal: 10.rpx),
                child:Column(
                children: [
                  Text(
                  widget.items[i],
                  style: TextStyle(
                      color: (i == widget.index)
                          ? const Color(0xFFFFFFFF)
                          : const Color(0xFF989EA4),
                      fontSize: 15.rpx,
                      fontWeight: (i == widget.index)
                          ? FontWeight.bold
                          : FontWeight.normal),
                ),
                i == widget.index?
                QGImage(asset: "xhuanzhaonf",width: 32.rpx)
                :SizedBox(height: 20.rpx,)
                ],
              ),
              )
              
              :
              Container(
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(horizontal: 12.rpx),
                decoration: i == widget.index
                    ? BoxDecoration(
                        color: const Color(0xFFffffff),
                        borderRadius: BorderRadius.circular(26.rpx),
                      )
                    : BoxDecoration(
                        
                        color:const Color(0xFF232A32),
                        borderRadius: BorderRadius.circular(26.rpx),
                      ),
                child: Text(
                  widget.items[i],
                  style: TextStyle(
                      color: (i == widget.index)
                          ? const Color(0xFF111111)
                          : const Color(0xFF989EA4),
                      fontSize: 11.rpx,
                      fontWeight: (i == widget.index)
                          ? FontWeight.bold
                          : FontWeight.normal),
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
